<?php
//http://kaifa.zq.zhongsou.com/api/alipay_return.php?body=%E4%B8%93%E4%B8%9A%E7%9A%84%E6%B5%8B%E8%AF%95&buyer_email=a_lost_cat520%40163.com&buyer_id=2088402423445114&exterface=create_direct_pay_by_user&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3InUFmSJO9LUm1gfsXqgCJJWhJCx%252F239cvSTJfvqQP3liXof9Idv&notify_time=2015-12-22+17%3A05%3A59&notify_type=trade_status_sync&out_trade_no=Y198273641520&payment_type=1&seller_email=2746371913%40qq.com&seller_id=2088121090018110&subject=%E6%B5%8B%E8%AF%95%E8%AE%A2%E5%8D%95&total_fee=0.01&trade_no=2015122221001004110089479574&trade_status=TRADE_SUCCESS&sign=8f5dbe0fcfd00398595be70acd91b079&sign_type=MD5
/*
Array
(
    [body] => http://zq.zhongsou.com/
    [buyer_email] => a_lost_cat520@163.com
    [buyer_id] => 2088402423445114
    [exterface] => create_direct_pay_by_user
    [is_success] => T
    [notify_id] => RqPnCoPT3K9%2Fvwbh3InUFmSG6ZtEemzkGzQLpkPha%2B%2BkRwZUA0%2BuA4xJFp2HVJNPWfiS
    [notify_time] => 2015-12-22 18:36:43
    [notify_type] => trade_status_sync
    [out_trade_no] => Y198273641522
    [payment_type] => 1
    [seller_email] => 2746371913@qq.com
    [seller_id] => 2088121090018110
    [subject] => 测试订单
    [total_fee] => 0.01
    [trade_no] => 2015122221001004110093510576
    [trade_status] => TRADE_SUCCESS
    [sign] => 58237f8001e7dd70954dd0fd1702b5a6
    [sign_type] => MD5
)
http://kaifa.zq.zhongsou.com/api/alipay_return.php?body=http%3A%2F%2Fkaifa.zq.zhongsou.com%2Findex.php&buyer_email=a_lost_cat520%40163.com&buyer_id=2088402423445114&discount=0.00&gmt_create=2015-12-23+11%3A10%3A30&gmt_logistics_modify=2015-12-23+11%3A10%3A30&gmt_payment=2015-12-23+11%3A10%3A47&is_success=T&is_total_fee_adjust=N&logistics_fee=0.00&logistics_payment=SELLER_PAY&logistics_type=EXPRESS&notify_id=RqPnCoPT3K9%252Fvwbh3InUFmtTvOqi5b8Qdfvnybxj1eJyCjPWzjRcym9NLEf4ufnOiQ48&notify_time=2015-12-23+11%3A10%3A51&notify_type=trade_status_sync&out_trade_no=Y201512221450839715&payment_type=1&price=0.01&quantity=1&receive_address=%E5%8C%97%E4%BA%AC%E5%B8%82%E5%B8%82%E8%BE%96%E5%8C%BA%E6%B5%B7%E6%B7%80%E5%8C%BA%E9%A6%96%E4%BA%AB%E7%A7%91%E6%8A%80%E5%A4%A7%E5%8E%A69%E5%B1%82&receive_mobile=18687655678&receive_name=%E4%B8%AD%E6%90%9C%E7%BD%91%E7%BB%9C%E6%8A%80%E6%9C%AF%E8%82%A1%E4%BB%BD%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8&receive_phone=010-62266296&receive_zip=000000&seller_actions=SEND_GOODS&seller_email=2746371913%40qq.com&seller_id=2088121090018110&subject=%E6%B5%8B%E8%AF%95%E8%AE%A2%E5%8D%95&total_fee=0.01&trade_no=2015122300001000110071527916&trade_status=WAIT_SELLER_SEND_GOODS&use_coupon=N&sign=61af5c6aa8f33db6f26a5661de454e01&sign_type=MD5
T2015122300001000110071520881utf-8EXPRESSsend_goods_confirm_by_platform2088121090018110D201512221450834780测试物流20884024234451140156[REFUND, CONFIRM_GOODS]a_lost_cat520@163.comPRIVATE_ACCOUNT2088402423445114interface/escrow2015-12-23 09:39:1715612015-12-23 09:39:40BY201512221450834724208812109001811020881210900181100156[EXTEND_TIMEOUT]2746371913@qq.comCORPORATE_ACCOUNT20881210900181100.000.0F0.01INST_PARTNER2015122300001000110071520881WAIT_BUYER_CONFIRM_GOODSS529a433a74e1c80b3d42bcf1056c63f9MD5
验证成功
Array
(
    [body] => http://kaifa.zq.zhongsou.com/index.php
    [buyer_email] => a_lost_cat520@163.com
    [buyer_id] => 2088402423445114
    [discount] => 0.00
    [gmt_create] => 2015-12-23 11:10:30
    [gmt_logistics_modify] => 2015-12-23 11:10:30
    [gmt_payment] => 2015-12-23 11:10:47
    [is_success] => T
    [is_total_fee_adjust] => N
    [logistics_fee] => 0.00
    [logistics_payment] => SELLER_PAY
    [logistics_type] => EXPRESS
    [notify_id] => RqPnCoPT3K9%2Fvwbh3InUFmtTvOqi5b8Qdfvnybxj1eJyCjPWzjRcym9NLEf4ufnOiQ48
    [notify_time] => 2015-12-23 11:10:51
    [notify_type] => trade_status_sync
    [out_trade_no] => Y201512221450839715
    [payment_type] => 1
    [price] => 0.01
    [quantity] => 1
    [receive_address] => 北京市市辖区海淀区首享科技大厦9层
    [receive_mobile] => 18687655678
    [receive_name] => 中搜网络技术股份有限公司
    [receive_phone] => 010-62266296
    [receive_zip] => 000000
    [seller_actions] => SEND_GOODS
    [seller_email] => 2746371913@qq.com
    [seller_id] => 2088121090018110
    [subject] => 测试订单
    [total_fee] => 0.01
    [trade_no] => 2015122300001000110071527916
    [trade_status] => WAIT_SELLER_SEND_GOODS
    [use_coupon] => N
    [sign] => 61af5c6aa8f33db6f26a5661de454e01
    [sign_type] => MD5
)
*/


/* * 
 * 功能：支付宝页面跳转同步通知页面
 * 版本：3.3
 * 日期：2012-07-23
 * 说明：
 * 以下代码只是为了方便商户测试而提供的样例代码，商户可以根据自己网站的需要，按照技术文档编写,并非一定要使用该代码。
 * 该代码仅供学习和研究支付宝接口使用，只是提供一个参考。

 *************************页面功能说明*************************
 * 该页面可在本机电脑测试
 * 可放入HTML等美化页面的代码、商户业务逻辑程序代码
 * 该页面可以使用PHP开发工具调试，也可以使用写文本函数logResult，该函数已被默认关闭，见alipay_notify_class.php中的函数verifyReturn
 */

require_once("../include/lxbase.class.php");
require_once("../include/alipay.class.php");
?>
<!DOCTYPE HTML>
<html>
    <head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
//计算得出通知验证结果
//session_start();
$body = urldecode(base64_decode($_GET['body']));
$tokenArr = explode('=', $body);
//print_r($tokenArr[5]);
$token = $tokenArr[5];

$sn = $_GET['out_trade_no'];

$alipayNotify = new Alipay($sn);
$verify_result = $alipayNotify->verifyReturn();
if($verify_result) {//验证成功
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//请在这里加上商户的业务逻辑程序代码
	
	//——请根据您的业务逻辑来编写程序（以下代码仅作参考）——
    //获取支付宝的通知返回参数，可参考技术文档中页面跳转同步通知参数列表

	//商户订单号

	$out_trade_no = $_GET['out_trade_no'];

	//支付宝交易号

	$trade_no = $_GET['trade_no'];

	//交易状态
	$trade_status = $_GET['trade_status'];
    
	if($_GET['trade_status'] == 'WAIT_SELLER_SEND_GOODS') {
	    //判断该笔订单是否在商户网站中已经做过处理
	    //如果没有做过处理，根据订单号（out_trade_no）在商户网站的订单系统中查到该笔订单的详细，并执行商户的业务程序
	    //如果有做过处理，不执行商户的业务程序
	    
	    /**************************请求参数**************************/
	    
	    //支付宝交易号
	    //$trade_no = $_POST['WIDtrade_no'];
	    //必填
	    
	    //物流公司名称
	    $logistics_name = '测试物流';
	    //必填
	    
	    //物流发货单号
	    
	    $invoice_no = 'D20151222'.time();
	    //物流运输类型
	    $transport_type = 'EXPRESS';
	    //三个值可选：POST（平邮）、EXPRESS（快递）、EMS（EMS）
	    
	    
	    /************************************************************/
	    
	    //构造要请求的参数数组，无需改动
	    $parameter = array(
	        "service" => "send_goods_confirm_by_platform",
	        "partner" => trim($alipayNotify->alipay_config['partner']),
	        "trade_no"	=> $trade_no,
	        "logistics_name"	=> $logistics_name,
	        "invoice_no"	=> $invoice_no,
	        "transport_type"	=> $transport_type,
	        "_input_charset"	=> trim(strtolower($alipayNotify->alipay_config['input_charset']))
	    );
	    
	    //建立请求
	    $html_text = $alipayNotify->buildRequestHttp($parameter);
	    //解析XML
	    //注意：该功能PHP5环境及以上支持，需开通curl、SSL等PHP配置环境。建议本地调试时使用PHP开发软件
	    $doc = new DOMDocument();
	    $doc->loadXML($html_text);
	    
	    //请在这里加上商户的业务逻辑程序代码
	    
	    //——请根据您的业务逻辑来编写程序（以下代码仅作参考）——
	    
	    //获取支付宝的通知返回参数，可参考技术文档中页面跳转同步通知参数列表
	    
	    //解析XML
	    if(!empty($doc->getElementsByTagName( "alipay" )->item(0)->nodeValue) ) {
	        $alipay = $doc->getElementsByTagName( "alipay" )->item(0)->nodeValue;
	        //echo $alipay;
	    }
	}
    else if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {
		//判断该笔订单是否在商户网站中已经做过处理
			//如果没有做过处理，根据订单号（out_trade_no）在商户网站的订单系统中查到该笔订单的详细，并执行商户的业务程序
			//如果有做过处理，不执行商户的业务程序
    }
    else {
      echo "trade_status=".$_GET['trade_status'];
    }
    //$exterface = $_GET['exterface'];
    //if ($exterface != 'create_direct_pay_by_user') {//如果是担保交易就自动确认发货
        
    //}
	//echo "上面的字符串表示自动发货成功，验证成功<br />下面是跳转链接<br />";
	//echo $body;
	echo "<script language='javascript'>alert('验证成功！');location.href='{$body}';</script>";
	//——请根据您的业务逻辑来编写程序（以上代码仅作参考）——
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
else {
    //验证失败
    //如要调试，请看alipay_notify.php页面的verifyReturn函数
    //echo "验证失败";
    echo "<script language='javascript'>alert('验证失败！');location.href='{$body}';</script>";
}
?>
        <title>支付宝即时到账交易接口</title>
	</head>
    <body>
    </body>
</html>